function parseItemsToAdd(itemsToAdd) {

    var items = [];

    itemsToAdd.each(function () {
        var color_id = $(this).attr('id').split('_')[1];
        var quantity = $(this).val();

        if (quantity > 0) {
            var color = {"color_id": color_id, "quantity":quantity};
            items.push(color);
        }
    });

    return JSON.stringify(items);
}

function add_fields(link, association, content) {
    var new_id = new Date().getTime();
    var regexp = new RegExp("new_" + association, "g");
    $(link).parent().before(content.replace(regexp, new_id));
}

function remove_fields(link) {
    $(link).prev("input[type=hidden]").val("1");
    $(link).closest(".fields").hide();
}